<template>
    <div class="songs">
        <tags  v-if="album || artist " :artist="artist" :album ="album"/>
        <musicList  v-if="songList" :songList="songList" :playListId = "playListId"/>
    </div>
</template>

<script>
import tags from '../../../components/common/search/tags'
import musicList from '../../../components/content/playList/musicList'
import {_getSearch,_getSearchMultimatch} from '../../../network/search'
import {_getSongtDetail} from '../../../network/detail'
import {dtFormat} from '../../../util/tool'
import bus from '../../../util/bus'
export default {
    name: 'songs',
    props: [

    ],
    data() {
        return {
            songList:[],
            playListId:0,
            album:null,
            artist:null,
        };
    },
    computed: {

    },
    created() {
        // bus.$on('searchFlag',(res => {
        //     if(res){
        //         this.$router.go(0)
        //     }
        // }))
        // 搜索结果
        this.getSearch(this.$route.query.keywords,100,0,1)
        // 最佳匹配
        this.getSearchMultimatch(this.$route.query.keywords)
    },
    mounted() {

    },
    updated() {
        
    },
    watch: {

    },
    methods: {
        // 搜索结果
        getSearch(keywords,limit,offset,type){
            let _this = this
            // 搜索结果
            _getSearch(keywords,limit,offset,type)
            .then(res => {
                let songCount = res.data.result.songCount
                this.$route.query.totalNum = songCount + "首单曲"
                res.data.result.songs.forEach((val) => {
                    _getSongtDetail(val.id)
                    .then(res => {
                        
                        _this.songList.push(res.data.songs[0])
                    })
                })
            })
        },
        // 最佳匹配
        getSearchMultimatch(keywords){
            _getSearchMultimatch(keywords)
            .then(res => {
                if(res.data.result.artist){
                    this.artist = res.data.result.artist[0]
                }
                if(res.data.result.album){
                    this.album = res.data.result.album[0]
                }
                
            })
        }

    },
    components: {
        tags,
        musicList
    },
};
</script>

<style scoped lang="less">
.songs{
    margin-top: 20px;
    .title{
        padding: 10px 40px;
        border-bottom: 1px solid;
    }
}
</style>
